import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:window_example/launch_url/launch_util.dart';

void main() {
  // Be sure to add this line if `PackageInfo.fromPlatform()` is called before runApp()
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
          useMaterial3: true,
        ),
        home: Scaffold(
          appBar: AppBar(
            backgroundColor: Theme.of(context).colorScheme.inversePrimary,
            title: const Text("打开应用"),
          ),
          body: Center(
            child: Column(
              children: [
                FilledButton(
                    onPressed: () {
                      LaunchUtils.launchURL("https://pub.dev/");
                    },
                    child: const Text("打开网页")),
                Padding(
                  padding: const EdgeInsets.all(10),
                  child: FilledButton(
                      onPressed: () {
                        LaunchUtils.launchAppByPath(
                            r"C:\Program Files\TecnoPcManager\TecnoPcManager\TecnoPcManager.exe");
                      },
                      child: const Text("根据路径打开exe")),
                ),
                Padding(
                  padding: const EdgeInsets.all(10),
                  child: FilledButton(
                      onPressed: () async {
                        final result = await Process.run('cmd', ['dir:D:/']); // 这里的'cmd'表示要运行的命令为Windows系统上的"cmd"命令，['dir']表示要执行的参数为"dir"（显示当前目录内容）
                        if (kDebugMode) {
                          print("result:${result.stdout}");
                        } // 输出命令执行结果的标准输出流
                      },
                      child: const Text("Process.run")),
                ),


                Padding(
                  padding: const EdgeInsets.all(10),
                  child: FilledButton(
                      onPressed: () async {
                        PackageInfo packageInfo = await PackageInfo.fromPlatform();
                        String appName = packageInfo.appName;
                        String packageName = packageInfo.packageName;
                        String version = packageInfo.version;
                        String buildNumber = packageInfo.buildNumber;
                        print("version:$version");
                        print("appName:$appName");
                        print("packageName:$packageName");
                        print("buildNumber:$buildNumber");
                      },
                      child: const Text("PackageInfo")),
                ),
              ],
            ),
          ),
        ));
  }
}
